package main

import (
	"encoding/json"
	"fmt"
)

type Stu struct {
	Name  string `json:"Name"`
	Age   int
	Sex   string
	Class *Class `json:"Class"`
}

type Class struct {
	Name  string
	Grade int
}

func main() {
	//实例化数据结构，用于生成json字符串
	var Class = Class{
		Name:  "literature",
		Grade: 9,
	}
	stu := Stu{
		Name:  "amy",
		Sex:   "女",
		Age:   18,
		Class: &Class,
	}

	fmt.Printf("stu: %v\n", stu)
	//生成json字符串
	jsonStu, err := json.Marshal(stu)
	if err != nil {
		fmt.Println("生成json字符串错误")
	}
	fmt.Println("jsonStu: \n", jsonStu)
	//jsonStu是[]byte类型，转化成string类型便于查看
	fmt.Println("string(jsonStu): \n", string(jsonStu))

	var result interface{}
	//将json字符串解码result
	err = json.Unmarshal(jsonStu, &result)
	if err != nil {
		fmt.Println("解析json字符串错误", err)
	}
	fmt.Println("result: \n", result)
	flow := &AutoGenerated{}
	json.Unmarshal([]byte(`{"flow_name": "测试流程中心模板", "flow_config": {"flow_id": "131313", "package_id": "31313", "flow_template_id": "131313"}, "flow_source": 0, "require_approval": true}`), flow)

	fmt.Println(*flow)

}

type AutoGenerated struct {
	FlowName        string `json:"flow_name"`
	RequireApproval bool   `json:"require_approvalss"`
	FlowConfigsss   string `json:"ss"`
	//FlowConfig struct {
	//	FlowID         string `json:"flow_id"`
	//	PackageID      string `json:"package_id"`
	//	FlowTemplateID string `json:"flow_template_id"`
	//} `json:"flow_config"`
	//FlowSource      string `json:"flow_source"`
	//RequireApproval bool   `json:"require_approval"`
}
